package com.example.dnfgamercommunitybackend.controller;

import com.example.dnfgamercommunitybackend.service.ManageUserService;
import org.apache.ibatis.annotations.Param;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
public class ManageUserController {
    @Resource
    private ManageUserService manageUserService;
    @PreAuthorize("hasAuthority('admin:get_user_list')")
    @GetMapping("/manage/getUserList")
    public String getUserList(){
        return manageUserService.getUserList();
    }

    @PreAuthorize("hasAuthority('admin:ban_user')")
    @GetMapping("/manage/banUser")
    public String banUserByUserId(@RequestParam("userId") int userId){
        return manageUserService.banUserByUserId(userId);
    }

    @PreAuthorize("hasAuthority('admin:allow_user')")
    @GetMapping("/manage/allowUser")
    public String allowUserByUserId(@RequestParam("userId") int userId){
        return manageUserService.allowUserByUserId(userId);
    }

    @PreAuthorize("hasAuthority('admin:delete_user')")
    @GetMapping("/manage/deleteUser")
    public String deleteUserById(@RequestParam("userId") int userId){
        return manageUserService.deleteUserById(userId);
    }

    @PreAuthorize("hasAuthority('admin:get_user_by_keyword')")
    @GetMapping("/manage/getUserByKeyword")
    public String getUserByKeyword(@RequestParam("keyword") String keyword){
        return manageUserService.getUserByKeyword(keyword);
    }

}
